package com.koron.css2.baseConfig.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.baseConfig.bean.TradeClassifyBean;
import com.koron.css2.baseConfig.mapper.TradeClassifyMapper;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.util.Constant;
import com.koron.util.JsonUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;
/**
 * 行业分类-添加
 * 
 * @author 李攀
 *
 */
public class TradeClassifyAdd implements ServerInterface{

	private static Logger logger = LogManager.getLogger(TradeClassifyAdd.class);

	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		TradeClassifyMapper mapper = factory.getMapper(TradeClassifyMapper.class,"_default");
		TradeClassifyBean bean = new TradeClassifyBean();
		try {
			bean = JsonUtils.objectToPojo(req.getData(), TradeClassifyBean.class);
		} catch (Exception e) {
			logger.error("非法参数", e);
			return MessageBean.create(Constant.ILLEGAL_PARAMETER, "非法参数", void.class);
		}
		// 校验字段重复
		if (mapper.check("trade_name", bean.getTradeName()) > 0) {
			return MessageBean.create(Constant.ILLEGAL_PARAMETER,"行业名称：" + bean.getTradeName() + "的信息已存在。", void.class);
		}
		bean.setCreateInfo(userInfo);
	
		mapper.insertTradeClassify(bean);
		return MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "success", void.class);
	}
	
}
